package cn.jimmie.learn.sdk;

import android.app.Activity;

import cn.jimmie.learn.pbc.resource.ISdk;
import cn.jimmie.learn.pbc.resource.Plugin;
import cn.jimmie.learn.pbc.resource.ShareInstance;
import cn.jimmie.learn.sdk.util.PluginUtils;

/**
 * function :
 *
 * <p> Create Time:  2019年02月14日 14:24 </p>
 * <p> @author Jimmie.Qian  </p>
 */
public final class SdkApi {
    private static ISdk mInstance;

    static void login(Activity activity, OnSdkLoginListener listener) {
        if (mInstance != null) mInstance.login(activity);
        ShareInstance.instance().setSdkLoginListener(listener);
    }

    static void init(Activity activity) {
        // 先使用旧包初始化, 后续进行升级检查
        Plugin plugin = PluginUtils.useDefaultPlugin(activity);

        ShareInstance.instance().setPlugin(plugin);
        // 从插件中获取单例
        mInstance = PluginUtils.hookPluginInstance(plugin.getPluginClassLoader());
    }

    public static void reloadSdk(ISdk instance) {
        mInstance = instance;
    }
}
